<?php 

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO htmlplug (id, judul, konten) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['judul'], "text"),
                       GetSQLValueString($_POST['konten'], "text"));

  mysql_select_db($database_konek, $konek);
  $Result1 = mysql_query($insertSQL, $konek) or die(mysql_error());

  $insertGoTo = "home.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  ?>
	
	 <script language="javascript">
  	<!--
     	    alert('Input Success')
			window.location = "<?php echo sprintf("%s", $insertGoTo) ?>";
			
   	--></script>
	<?php
}

mysql_select_db($database_konek, $konek);
$query_plugtext = "SELECT * FROM htmlplug ORDER BY id ASC";
$plugtext = mysql_query($query_plugtext, $konek) or die(mysql_error());
$row_plugtext = mysql_fetch_assoc($plugtext);
$totalRows_plugtext = mysql_num_rows($plugtext);
?>
<?php if ($totalRows_plugtext > 0) { // Show if recordset not empty ?>
  <table  id="example-datatable" class="table table-bordered table-hover dataTable" aria-describedby="example-datatable_info" >
    <tr>
      <td width="50">id</td>
      <td>judul</td>
      <td>konten</td>
      <td width="50">Actions</td>
    </tr>
    <?php do { ?>
      <tr>
        <td><?php echo $row_plugtext['id']; ?></td>
        <td><?php echo $row_plugtext['judul']; ?></td>
        <td><?php echo $row_plugtext['konten']; ?></td>
        <td><div class="btn-group">
  <a href="home.php?page=pluginview&p=<?php echo $_GET['p'] ?>&root=edit_module.php&id=<?php echo $row_plugtext['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Edit"><i class="fa fa-pencil"></i></a>
  <a href="home.php?page=pluginview&p=<?php echo $_GET['p'] ?>&root=delete.php&id=<?php echo $row_plugtext['id']; ?>" data-toggle="tooltip" title="" class="btn btn-xs btn-default" data-original-title="Delete"><i class="fa fa-times"></i></a>
</div></td>
      </tr>
      <?php } while ($row_plugtext = mysql_fetch_assoc($plugtext)); ?>
  </table>
  <?php } // Show if recordset not empty ?>
  <p>&nbsp;</p>
  <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
    <table width="100%" align="center">
      <tr valign="baseline">
        <td width="12%" align="left" valign="top" nowrap="nowrap"><strong>Judul:</strong></td>
        <td width="88%"><input type="text" name="judul" class="form-control" value="" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td align="left" valign="top" nowrap="nowrap"><strong>Konten:</strong></td>
        <td><textarea name="konten" cols="32" rows="6" class="form-control" ></textarea></td>
      </tr>
      <tr valign="baseline">
        <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
        <td><input type="submit" value="Submit" id="status-update-btn" class="btn btn-primary pull-right" /></td>
      </tr>
    </table>
    <input type="hidden" name="id" value="" />
    <input type="hidden" name="MM_insert" value="form1" />
</form>

<?php

mysql_free_result($plugtext);
?>
